package com.fingard.dsp.web;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.fingard.FGBiz;
import com.fingard.net.niosocket.ServerSocketNio;

public class HttpServer {

	private ServerSocketNio httpServerNio;
	private ExecutorService execService;
	private ThreadPoolExecutor thdPool = null;
	public HttpServer(int p_listenPort){
		thdPool = new ThreadPoolExecutor(5, 10,
                60L, TimeUnit.SECONDS,
                new LinkedBlockingQueue<Runnable>());//5个线程足矣，最大10个
		thdPool.allowCoreThreadTimeOut(true);
		execService = thdPool;
		httpServerNio = new ServerSocketNio(p_listenPort, 100, execService, HttpRunnable.class, "http", "utf-8");
	}
	
	public void start(){
		new Thread(httpServerNio).start();
	}
	
	public String stop(){
		String stop1="";
		try{
			stop1 = httpServerNio.stop();
		}catch(Throwable e){
			FGBiz.limitMsg.exception("HttpServer.stop", e);
		}
		try{
			thdPool.shutdown();
		}catch(Throwable e){
			FGBiz.limitMsg.exception("HttpServer.stop", e);
		}
		return stop1;
	}
}
